package com.zeng.sys.filemd.servicemodule.vo;

import com.zeng.nicecore.convert.AbstractConvertor;
import com.zeng.nicecore.util.BeanUtil;
import com.zeng.nicecore.validation.ValidGroup;
import com.zeng.sys.filemd.servicemodule.entity.FileServer;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.Null;
import java.util.Date;
import java.util.List;
import java.util.Set;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
public class FileServerVo {
    //服务器名称
    private String name;
    //服务器标识
    private String flag;
    //服务器配置
    private String serverOption;
    //服务器状态
    private String status;

    //
    private Set<String> codes;

    @Null(groups = ValidGroup.add.class,message = "version must be empty when adding records ")
    private Integer version;

    @Null(groups = ValidGroup.add.class,message = "valid must be empty when adding records ")
    private Short valid;

    @Null(groups = ValidGroup.add.class,message = "code must be empty when adding records")
    @NotEmpty(groups = ValidGroup.update.class,message = "code must be excluded where update record ")
    private String code;

    @Null(groups = ValidGroup.add.class,message = "id must be empty when adding records")
    private Integer id;

    @Null(groups = ValidGroup.add.class,message = "updateDate must be empty when adding records")
    private Date updateDate;

    @Null(groups = ValidGroup.add.class,message = "insertDate must be empty when adding records")
    private Date insertDate;

    public FileServer convertToFileServer(){
        return new FileServerVoConvertable().voToBean(this);
    }

    public static FileServerVo convertToFileServerVo(FileServer fileServer){
        return new FileServerVoConvertable().beanToVo(fileServer);
    }

    public static List<FileServerVo> listFileServerVo(List<FileServer> fileServers){
        return new FileServerVoConvertable().toList(fileServers);
    }

    public static List<FileServer> listFileServer(List<FileServerVo> fileServerVos){
        return new FileServerVoConvertable().toBeanList(fileServerVos);
    }

    private static class FileServerVoConvertable implements AbstractConvertor<FileServer, FileServerVo> {

        @Override
        public FileServerVo beanToVo(FileServer fileServer) {
            return BeanUtil.beanToVo(fileServer, new FileServerVo());
        }
    
        @Override
        public FileServer voToBean(FileServerVo fileServerVo) {
            return BeanUtil.VoToBean(fileServerVo, new FileServer());
        }
    }
}